package com.aptoto.thrift.alone;

import org.apache.thrift.TException;
import org.apache.thrift.protocol.TField;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.protocol.TType;
import org.apache.thrift.scheme.StandardScheme;

import com.aptoto.thrift.config.ThriftStructFieldConfig;

public class ThriftDynamicStandardScheme extends StandardScheme<ThriftDynamicStruct> {
	private final String structIdentifier;
	
	public ThriftDynamicStandardScheme(String structIdentifier) {
		super();
		this.structIdentifier = structIdentifier;
	}

	@Override
	public void read(TProtocol iproto, ThriftDynamicStruct struct) throws TException {
		TField schemeField;
		iproto.readStructBegin();
		while (true) {
			schemeField = iproto.readFieldBegin();
			if (schemeField.type == TType.STOP)
				break;
			ThriftStructFieldConfig field = ThriftStructFieldConfig.getThriftStructFieldConfig(structIdentifier, schemeField.id);
			if ( schemeField.type == field.fieldType ) {
				/** ★
				 * struct.[field] = iproto.readI32()/readString()/......;
				 * EncodingUtils.setBit(0, 0, true);//????
				 */
			}
		}
	}

	@Override
	public void write(TProtocol oproto, ThriftDynamicStruct struct) throws TException {
		// TODO Auto-generated method stub
		
	}
	
	public static void main(String[] args) {
		final int __AA_ISSET_ID = 0;
		final int __BB_ISSET_ID = 1;
		final int __CC_ISSET_ID = 2;
		final int __DD_ISSET_ID = 3;
		final int __EE_ISSET_ID = 4;
		final int __FF_ISSET_ID = 5;
		byte __isset_bitfield = 0;
		__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __AA_ISSET_ID, true);
		System.out.println(__isset_bitfield);
		__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __BB_ISSET_ID, true);
		System.out.println(__isset_bitfield);
		__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __CC_ISSET_ID, true);
		System.out.println(__isset_bitfield);
		__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __DD_ISSET_ID, true);
		System.out.println(__isset_bitfield);
		__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __EE_ISSET_ID, true);
		System.out.println(__isset_bitfield);
//		__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __FF_ISSET_ID, true);
//		System.out.println(__isset_bitfield);
		
		System.out.println("-------------------------");
		
		__isset_bitfield = 0;
		__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __DD_ISSET_ID, true);
		System.out.println(__isset_bitfield);
		__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __CC_ISSET_ID, true);
		System.out.println(__isset_bitfield);
		__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __AA_ISSET_ID, true);
		System.out.println(__isset_bitfield);
//		__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __FF_ISSET_ID, true);
//		System.out.println(__isset_bitfield);
		__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __EE_ISSET_ID, false);
		System.out.println(__isset_bitfield);
		__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __BB_ISSET_ID, true);
		System.out.println(__isset_bitfield);
		__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __EE_ISSET_ID, true);
		System.out.println(__isset_bitfield);
//		__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __AA_ISSET_ID, true);
//		System.out.println(__isset_bitfield);
//		__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __AA_ISSET_ID, true);
//		System.out.println(__isset_bitfield);
		
	}
}
